{ "cells": [ { "cell_type": "code", "execution_count": 10, "id": "2feeb277", "metadata": {}, "outputs": [], "source": [ "def get_distribution(samples, variables=None):\n", " \"\"\"\n", " For marginal distribution, P(A): get_distribution(samples, variables=['A'])\n", " For joint distribution, P(A, B): get_distribution(samples, variables=['A', 'B'])\n", " \"\"\"\n", " if variables is None:\n", " raise ValueError(\"variables must be specified\")\n", "\n", " return samples.groupby(variables).size() / samples.shape[0]" ] }, { "cell_type": "code", "execution_count": 24, "id": "cdb2e2f1", "metadata": {}, "outputs": [], "source": [ "# Define a model\n", "from pgmpy.factors.discrete import TabularCPD\n", "\n", "from pgmpy.utils import get_example_model\n", "\n", "alarm = get_example_model(\"alarm\")" ] }, { "cell_type": "markdown", "id": "d3219f21", "metadata": {}, "source": [ "# Normal Bayesian Network (no time variation)" ] }, { "cell_type": "markdown", "id": "6c064112", "metadata": {}, "source": [ "## Normal simulation" ] }, { "cell_type": "code", "execution_count": 28, "id": "94e02da7", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0ce37073bf334951ad58a6eff0d1da43", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/37 [00:00